<?php
namespace app\api\controller;
use think\Controller;
use think\Db;
use think\Request;
use think\View;
use think\Paginator;
use app\api\logic\Abouts;

class About extends Index
{
    public function __construct(Request $request){
        parent::__construct($request);
    }
    /**
    * 集团
    */
    public function blocDetail(Request $request)
    {   
        $navid['navid']=input('navid');
        $navuid='';
        if(input('navuid')==null || input('navuid')==''){
            $navuid=$this->blocs()->blocsNavuid($navid);
            $where['navuid']=$navuid;
            $bloc=$this->blocs()->blocsList($where);
        }else{
            $where['navuid']=input('navuid');
            $navuid=input('navuid');
            $bloc=$this->blocs()->blocsList($where);
        }
        $navuname=$this->blocs()->navuname($where);
        $this->navuHref($navid);
        $this->assign('navuname',$navuname);
        $this->assign('navuid',$where);
        $this->assign('bloc',$bloc);
        $this->assign('title','天津博顿集团');
        if($navuid==3){
            return view('honor');    
        }elseif($navuid==2){
            return view('lishi');
        }elseif($navuid==5){
            return view('culture');
        }else{
            return view('bloc');
        }

    }

    /**
    * 新闻
    */
    public function newslist()
    {
        $navid['navid']=input('navid');
        $where['newstype']=input('newstype','12');
        $page=Db::name('news')->order('newstime desc')->where($where)->paginate(4,false,['type'=>'bootstrap','var_page' => 'page']);
        $news=$page->all();
        $this->navuHref($navid);
        $this->assign('page',$page);
        $this->assign('news',$news);
        $this->assign('title','天津博顿集团');
        return view('newslist');
    }
    /**
    * 新闻详情
    */
    public function newsDetail()
    {
        $where['newsid']=input('newsid');
        $navid['navid']=input('navid');
        $newsdetail=Db::name('news')->where($where)->find();
        $this->navuHref($navid);
        $this->assign('news',$newsdetail);
        $this->assign('navid',$navid);
        $this->assign('title',$newsdetail['newstitle']);
        return view('newsdetail');
    } 
    /**
    * 控股企业
    */
    public function qiYe()
    {
        $navid['navid']=input('navid');
        if(input('navuid')==null || input('navuid')==''){
            $navuid=Db::name('ApiNavu')->where($navid)->select();
            foreach ($navuid as $key => $value) {
                $where['navuid']=$navuid[$key]['navuid'];
                $qiye[]=Db::name('NavDetail')->where($where)->find();
            }
            $this->assign('qiye',$qiye);
            $this->navuHref($navid);

            $this->assign('title','天津博顿集团');
            return view('qiyelist');
        }else{
            $where['navuid']=input('navuid');
            $qiye=$this->blocs()->blocsList($where);
        }
        $this->navuHref($navid);
        $this->assign('qiye',$qiye);
        $this->assign('title','天津博顿集团');
        return view('qiye');

    }
    /**
    * 产品展示
    */
    public function chanPin()
    {
        $navid['navid']=input('navid');
        $chanpintype=input('navuid');
        // $where['mintype']=input('mintype');
        // input('mintype')==''?$where['chanpintype']=input('navuid'):$where['mintype']=input('mintype');
        if(input('mintype')!=''){
            $where['mintype']=input('mintype');
            if($where['mintype']==31){
                $where['mintype']=33;
            }elseif($where['mintype']==32){
                $where['mintype']=36;
            }
        }else{
            $where['chanpintype']=input('navuid');
        }
        $chanpin=Db::name('chanpin')->order('chanpintime desc')->where($where)->select();
        // if(empty($cp)){
        //     $wheres['chanpintype']=input('navuid');
        //     $chanpin=Db::name('chanpin')->where($wheres)->select();
        // }else{
        //     $chanpin=$cp;
        // }
        $name=Db::name('ApiNavu')->where(['navuid'=>input('fnavuid')])->value('navuname');
        $this->navuHref($navid);
        $this->assign('name',$name);
        $this->assign('chanpintype',$chanpintype);
        $this->assign('chanpin',$chanpin);
        $this->assign('title','天津博顿集团');
        return view('chanpin');
    }
    public function chanpin_ajax()
    {
        // $where['mintype']=input('mintype');
        if(input('mintype')!=''){
            $where['mintype']=input('mintype');
            if($where['mintype']==31){
                $where['mintype']=33;
            }elseif($where['mintype']==32){
                $where['mintype']=36;
            }
        }else{
            $where['chanpintype']=input('navuid');
        }
        $chanpins=Db::name('chanpin')->order('chanpintime desc')->where($where)->select();
        // if(empty($chanpin)){
        //     $wheres['chanpintype']=input('navuid');
        //     $chanpins=Db::name('chanpin')->where($wheres)->select();
        // }else{
        //     $chanpins=$chanpin;
        // }
        $chanpins['name']=Db::name('ApiNavu')->where(['navuid'=>input('fnavuid')])->value('navuname');
        sort($chanpins);
        echo json_encode($chanpins);
    }
    /**
    * 产品详情
    */
    public function chanpinDetail()
    {
        $where['chanpinid']=input('chanpinid');
        $navid['navid']=input('navid');
        $chanpindetail=Db::name('chanpin')->where($where)->find();
        $chanpin=Db::name('chanpin')->order('chanpinid desc')->limit(5)->select();
        $this->navuHref($navid);
        $this->assign('chanpin',$chanpin);
        $this->assign('chanpindetail',$chanpindetail);
        $this->assign('navid',$navid);
        $this->assign('title',$chanpindetail['chanpinname']);
        return view('chanpindetail');
    }
    /**
    *博顿优势
    */ 
    public function youshi(){
        $navid['navid']=input('navid');
        $navuid='';
        if(input('navuid')==null || input('navuid')==''){
            $navuid=$this->blocs()->blocsNavuid($navid);
            $where['navuid']=$navuid;
            $bloc=$this->blocs()->blocsList($where);
        }else{
            $where['navuid']=input('navuid');
            $navuid=input('navuid');
            $bloc=$this->blocs()->blocsList($where);
            
        }
        $navuname=$this->blocs()->navuname($where);
        $this->navuHref($navid);
        $this->assign('navuname',$navuname);
        $this->assign('navuid',$where);
        $this->assign('bloc',$bloc);
        $this->assign('title','博顿优势');
        if(input('navuid')==28){
            return view('hezuo');
        }else{
            return view('youshi');
        }
    }
    /**
    * 合作伙伴
    */
    public function heZuo()
    {
        $hezuo=Db::name('cooperation')->select();
        $this->assign('hezuo',$hezuo);
        $this->assign('title','天津博顿集团');
        return view('hezuo');
    }
    /**
    * 联系我们
    */
    public function lianxi()
    { 
        $navid=input('navid');
        if(input('navuid')=='' || input('navuid')==null){
            $where['navid']=$navid;
            $navuid=$this->blocs()->blocsNavuid($where);

        }else{
            $navuid=input('navuid');
        }
        if($navuid==14){
            $lianxi=Db::name('NavDetail')->where('navuid = 0')->find();
            $this->assign('lianxi',$lianxi);
            $this->assign('title','天津博顿集团');
            return view('lianxi');
        }else{
            //人才招聘
            $this->zhaoPin();
            return view('zhaopin');
        }

    }
    /**
    * 人才招聘
    */ 
    private function zhaoPin()
    {
        $navid['navid']=input('navid');
        $page=Db::name('zhaopin')->paginate(4,false,['type'=>'bootstrap','var_page' => 'page']);
        $zhaopin=$page->all();
        $this->navuHref($navid);
        $this->assign('zhaopin',$zhaopin);
        $this->assign('page',$page);
        $this->assign('title','天津博顿集团');
    }
    /**
    * 人才招聘详情
    */
    public function zhaopindetail()
    {
        $where['zhaopinid']=input('zhaopinid');
        $navid['navid']=input('navid');
        $zhaopindetail=Db::name('zhaopin')->where($where)->find();
        $zhaopin=Db::name('zhaopin')->select();
        $this->navuHref($navid);
        $this->assign('zhaopin',$zhaopin);
        $this->assign('zhaopindetail',$zhaopindetail);
        $this->assign('title',$zhaopindetail['zhaopintitle']);
        return view('zhaopindetail');
    } 
    /**
    * 实例化类
    */
    private function blocs()
    {
        $nav=new Abouts();
        return $nav;
    }
    /**
    * 页面子导航
    */
    private function navuHref($navid)
    {
        $navu=$this->blocs()->blocsNavu($navid);
        $href=$this->blocs()->blocsNavHref($navid);
        $this->assign('navu',$navu);
        $this->assign('href',$href);
    } 
}